package com.alibaba.aone.casestudy.module.action;

import static com.alibaba.citrus.turbine.util.TurbineUtil.getTurbineRunData;

import java.sql.Timestamp;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Date;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;

import com.alibaba.aone.casestudy.common.entity.Action;
import com.alibaba.aone.casestudy.service.ActionService;
import com.alibaba.citrus.service.form.Form;
import com.alibaba.citrus.turbine.Context;
import com.alibaba.citrus.turbine.TurbineRunDataInternal;
import com.alibaba.intl.test.treedb.JsonObjectUtils;

public class ActionProcessAction {

	@Autowired
	private HttpServletRequest request;
	@Autowired
	private ActionService actionService;

	public void doEdit(Context context) {

		System.out.println(context.get("fault_person"));
		System.out.println(request.getParameter("category"));
		System.out.println(request.getParameter("sites"));
		System.out.println(request.getParameter("chargeman"));
		System.out.println(request.getParameter("follower"));
		System.out.println(request.getParameter("latestCompleteTime"));
		System.out.println("actionnumber: " + request.getParameter("actionNo"));

		String actionNo = request.getParameter("actionNo");
		String category = request.getParameter("category");
		String sites = request.getParameter("sites");
		String chargeman = request.getParameter("chargeman");
		String follower = request.getParameter("follower");
		String latestCompleteTime = request.getParameter("latestCompleteTime");
		Action action = actionService.getActionByNumber(actionNo);
		//action.setCategory(category);
		action.setChargeman(chargeman);
		action.setFollower(follower);
		String date = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(new Date("04/22/2011"));
		action.setLatestCompleteTime(Timestamp.valueOf(date));
		//action.setLatestCompleteTime(new Timestamp(0));
		actionService.updateAction(action);
		
		TurbineRunDataInternal rundata = (TurbineRunDataInternal) getTurbineRunData(request);
		rundata.forwardTo("actionDetailView.vm").withParameter("actionNo", action.getNumber());
	}

	public void doTest(Form form) {
		System.out.println(form.getKey());
		System.out.println(form.getGroups());
	}
	
	public static void main(String[] args) {
		/*Date date = new Date("04/22/2011");
		System.out.println();
		System.out.println(new SimpleDateFormat("yyyy-mm-dd hh:mm:ss").format(new Date("04/22/2011")));
		System.out.println(new SimpleDateFormat().format(new Date("04/29/2011")));
		System.out.println(new SimpleDateFormat("MM/dd/yyyy").format(new Date("04/22/2011")));
		DateFormat f = DateFormat.getDateInstance(0);
		SimpleDateFormat ff = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss");
		ff.format(date);
		System.out.println(ff.format(date));*/
		//System.out.println(JsonObjectUtils.isSameObject(new int[2], new int[2], new String[]{"length"}, false));
	}

}
